
class EventEmit {
  constructor(){
    this.events = {}
  }


  on(eventName,callback){
    const callbacks = this.events[eventName] ||[]
    callbacks.push(callback)
    this.events[eventName]=callbacks
  }

  emit(eventName,...args){
    this.events[eventName].callbacks.forEach(cb=>{
      cb(args)
    })
  }

  off(eventName,callback){
    const index = this.events[eventName].callbacks.indexOf(callback)
    if(index!=-1){
      this.events[eventName].callbacks.splice(index,1)
    }
  }

  once(evntName,callback){
    const one = ((...arg)=>{
      callback(...arg)
      this.off(evntName,callback)
    })
    this.on(eventName,one)
  }
}

function f1(...args){
  console.log(args);
  console.log(...args);
}

f1(1,2,3)